<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<!--<link th:href="@{/ajax/libs/laydate/laydate.css}" rel="stylesheet"/>-->
<script th:src="@{/ajax/libs/laydate/laydate.js}"></script>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-student-add">
        <input name="classId"  type="hidden" id="classId"/>
        <hr/>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">宿舍号：</label>
                <div class="col-sm-6 input-group">
                    <input id="dormitory" name="dormitory" class="form-control" type="text">
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">走读生：000</span>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">班级名称：</label>
                <div class="col-sm-6 input-group">
                    <input class="form-control"  type="text" name="classNo" onclick="selectList()"  id="className">
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">eg:20级4班</span>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">学员姓名：</label>
                <div class="col-sm-6 input-group">
                    <input id="studentName" name="studentName" class="form-control" type="text">
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">学员性别：</label>
                <div class="col-sm-6 input-group">
                    <select id="studentSex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">身份证号：</label>
                <div class="col-sm-6 input-group">
                    <input id="idCardNo" name="idCardNo" class="form-control" type="text">
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">出生日期：</label>
                <div class="col-sm-6 input-group">
                    <input id="birthday" name="birthday" class="form-control" type="text">
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">籍贯：</label>
                <div class="col-sm-6 input-group">
                    <input id="nativePlace" name="nativePlace" class="form-control" type="text">
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">通讯地址：</label>
                <div class="col-sm-6 input-group">
                    <input id="address" name="address" class="form-control" type="text">
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>

                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">学历：</label>
                <div class="col-sm-6 input-group">
                    <select id="education" class="form-control m-b" th:with="type=${@dict.getType('teach_education')}">
                        <!--<option value="">请选择</option>-->
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">邮政编码：</label>
                <div class="col-sm-6 input-group">
                    <input id="postalCode" name="postalCode" value="250000" class="form-control" type="text">
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">电话：</label>
                <div class="col-sm-6 input-group">
                    <input id="phone" name="phone" class="form-control" type="text">
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">父亲电话：</label>
                <div class="col-sm-6 input-group">
                    <input id="studentFatherPhone" name="studentFatherPhone" class="form-control" type="text">
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">母亲电话：</label>
                <div class="col-sm-6 input-group">
                    <input id="studentMotherPhone" name="studentMotherPhone" class="form-control" type="text">
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">邮箱：</label>
                <div class="col-sm-6 input-group">
                    <input id="mail" name="mail" class="form-control" type="text">
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">入学时间：</label>
                <div class="col-sm-6 input-group">
                    <input id="startTime" name="startTime" class="form-control" type="text">
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">毕业时间：</label>
                <div class="col-sm-6 input-group">
                    <input id="graduateDate" name="graduateDate" class="form-control" type="text" placeholder="yyyy-MM-dd">
                    <!-- <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>-->
                </div>
            </div>
        </div>


        <br/>
        <hr />
        <!--<div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">任课老师：</label>
                <div class="col-sm-6 input-group">
                    <input id="studentNamePinyin" name="studentNamePinyin" class="form-control" type="text">
                    &lt;!&ndash;                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>&ndash;&gt;
                </div>
            </div>
        </div>-->

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">班主任：</label>
                <div class="col-sm-6 input-group">
                    <input id="trafficPermit" name="trafficPermit" class="form-control" type="text">
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">是否单亲：</label>
                <div class="col-sm-6 input-group">
                    <select id="singleParent" name="singleParent" class="form-control m-b">
                        <option value="0" selected>否</option>
                        <option value="1">是</option>
                    </select>
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">学员状态：</label>
                <div class="col-sm-6 input-group">
                    <select id="status" class="form-control m-b" th:with="type=${@dict.getType('teach_status')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                    <span class="input-group-addon" style="color: red;background-color: #EEEEEE">*</span>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">项目地址：</label>
                <div class="col-sm-6 input-group">
                    <input id="postname" name="postname" class="form-control" type="text">
                </div>
            </div>
        </div>


        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">教材编号：</label>
                <div class="col-sm-6 input-group">
                    <input id="textbookNo" name="textbookNo" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">就业意向：</label>
                <div class="col-sm-6 input-group">
                    <!--<input id="jobCity" name="jobCity" class="form-control" type="text">-->
                    <select id="jobCity" class="form-control m-b" th:with="type=${@dict.getType('teach_job_city')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">缴费金额：</label>
                <div class="col-sm-6 input-group">
                    <input id="workExperience" name="workExperience" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">学员来源：</label>
                <div class="col-sm-6 input-group">
                    <select id="extend1" class="form-control m-b" th:with="type=${@dict.getType('teach_student_source')}">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">是否有基础：</label>
                <div class="col-sm-6 input-group">
                    <select id="base" class="form-control m-b" th:with="type=${@dict.getType('teach_basic')}">
                        <option value="">请选择</option>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">英语水平：</label>
                <div class="col-sm-6 input-group">
                    <!--<input id="englishLevel" name="englishLevel" class="form-control" type="text">-->
                    <select id="englishLevel" class="form-control m-b" th:with="type=${@dict.getType('teach_english_level')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">与紧急联系人关系：</label>
                <div class="col-sm-6 input-group">
                    <input id="emergencyContact" name="emergencyContact" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">紧急联系人电话：</label>
                <div class="col-sm-6 input-group">
                    <input id="emergencyContactPhone" name="emergencyContactPhone" class="form-control" type="text">
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="form-group">
                <label class="col-sm-5 control-label">备注：</label>
                <div class="col-sm-6 input-group">
                    <input id="extend2" name="extend2" class="form-control" type="text">
                </div>
            </div>
        </div>


    </form>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    var prefix = ctx + "teach/student";

    $("#form-student-add").validate({
        rules: {
            // kgcUid:{
            //     required:true,
            //     /*remote: {
            //         url: prefix + "/checkKgcUnique",
            //         type: "post",
            //         dataType: "json",
            //         data: {
            //             "classNo": function() {
            //                 return $.common.trim($("#classId").val());
            //             },
            //             "kgcUid": function() {
            //                 return $.common.trim($("#kgcUid").val());
            //             }
            //         },
            //         dataFilter: function(data, type) {
            //             return $.validate.unique(data);
            //         }
            //     }*/
            // },
            studentName: {
                required: true
            },
            startTime:{
                required: true
            },
            // kgcNo:{
            //     required: true
            // },
            // kgcNickname:{
            //     required: true
            // },
            // postname:{
            //     required: true
            // },
            idCardNo:{
                required: true
            },
            phone:{
                required: true
            },
            address:{
                required: true
            }
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.ajax({
                cache : true,
                type : "POST",
                url : prefix + "/checkKgcUnique",
                data : {
                    "classNo": $.common.trim($("#classId").val()),
                    "kgcUid": $.common.trim($("#kgcUid").val())
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.validate.unique(data);
                    //console.log($.validate.unique(data))
                    if($.validate.unique(data) == false){
                        layer.alert("此学生该专业已存在");
                        return;
                    }else {
                        add();
                    }
                }
            });
        }
    }

    function add() {
        // var studentId = $("input[name='studentId']").val();
        var classId = $("input[name='classId']").val(); //班级编号
       //var kgcNo = $("input[name='kgcNo']").val();  //课工场编号
        //var kgcUid = $("input[name='kgcUid']").val();  //课工场UID
        //var kgcNickname = $("input[name='kgcNickname']").val();  //课工场名称
        var status = $("#status option:selected").val();  //状态
        var startTime = $("#startTime").val();  //进班时间
        var postname = $("input[name='postname']").val();  //学生项目地址
        var studentName = $("input[name='studentName']").val();  //学生姓名
        var studentSex = $("#studentSex option:selected").val();  //学生性别
        var nativePlace = $("input[name='nativePlace']").val();  //籍贯
        var idCardNo = $("input[name='idCardNo']").val();  //身份证号
        var education = $("#education option:selected").val();  //学历
        var phone = $("input[name='phone']").val();  //电话
        var mail = $("input[name='mail']").val();  //邮箱
        var address = $("input[name='address']").val();  //地址
       // var studentFatherName = $("input[name='studentFatherName']").val();
        var studentFatherPhone = $("input[name='studentFatherPhone']").val();
        //var studentFatherUnit = $("input[name='studentFatherUnit']").val();
        //var studentMotherName = $("input[name='studentMotherName']").val();
        var studentMotherPhone = $("input[name='studentMotherPhone']").val();
       // var studentMotherUnit = $("input[name='studentMotherUnit']").val();
        //var studentAnotherName = $("input[name='studentAnotherName']").val();
        var singleParent = $("#singleParent option:selected").val();
        var graduateInstitutions = $("input[name='graduateInstitutions']").val();  //毕业院校
        var workExperience = $("input[name='workExperience']").val();  //学前工作经历
        var base = $("#base option:selected").val();  //是否有基础
        var englishLevel = $("#englishLevel option:selected").val();  //英语水平
        var degreeInNature = $("#degreeInNature option:selected").val();  //学历性质
        var graduateDate = $("#graduateDate").val();  //毕业时间
        //var major = $("input[name='major']").val();  //学前专业
        var extend1 = $("#extend1 option:selected").val();  //学员来源
        var extend2 = $("input[name='extend2']").val();  //备注
        var emergencyContact = $("#emergencyContact").val();  //与紧急联系人关系
        var emergencyContactPhone = $("#emergencyContactPhone").val();  //紧急联系人电话
        var postalCode = $("input[name='postalCode']").val();  //邮政编码
        //var studentNamePinyin = $("input[name='studentNamePinyin']").val();  //任课老师
        var trafficPermit = $("input[name='trafficPermit']").val();  //班主任
        var textbookNo = $("input[name='textbookNo']").val();  //教材编号
        var jobCity = $("#jobCity option:selected").val();   //就业意向城市

        $.ajax({
            cache : true,
            type : "POST",
            url : prefix + "/add",
            data : {
                // "studentId": studentId,
                "classNo": classId,
                "status": status,
                "startTime": startTime,
                "postname": postname,
                "studentName": studentName,
                "studentSex": studentSex,
                "nativePlace": nativePlace,
                "idCardNo": idCardNo,
                "education": education,
                "phone": phone,
                "mail": mail,
                "address": address,
                "graduateInstitutions": graduateInstitutions,
                "workExperience": workExperience,
                "base": base,
                "englishLevel": englishLevel,
                "degreeInNature": degreeInNature,
                "graduateDate": graduateDate,
                "extend1":extend1,
                "extend2":extend2,
                "emergencyContact":emergencyContact,
                "emergencyContactPhone":emergencyContactPhone,
                "postalCode":postalCode,
              //  "studentNamePinyin":studentNamePinyin,
                "trafficPermit":trafficPermit,
                "textbookNo":textbookNo,
                "jobCity":jobCity,
                "singleParent":singleParent
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.successCallback(data);
            }
        });
    }

    $(function(){
        //时间选择器
        laydate.render({
            elem: '#startTime',trigger: 'click'
        });

            //时间选择器
            laydate.render({
                elem: '#birthday',trigger: 'click'
            });
        //时间选择器
        laydate.render({
            elem: '#graduateDate',trigger: 'click'
        });
    });

    /*学生管理-新增-选择班级*/
    function selectList() {
        var url = ctx + "teach/teachClasses/selectList";
        var options = {
            title: '选择班级',
            width: "800",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }


    function doSubmit(index, layero){
        var body = layer.getChildFrame('body', index);
        var data = body.find('.selected')[0];
        if(data != "undefined" && data != "" && data != null){
            $("#className").val(body.find('.selected')[0].children[2].innerHTML);
            $("#classId").val(body.find('.selected')[0].children[1].innerHTML);
        }else{
            layer.msg("请选择一个班级");
        }
        layer.close(index);
    }

</script>
</body>
</html>
